//
//  LJProfessionalAnswerCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/11.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "GYRollingNoticeView.h"
#import "MineRecNoticeCell.h"

#import "LJProfessionalAnswerCell.h"

@interface LJProfessionalAnswerCell()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,GYRollingNoticeViewDataSource, GYRollingNoticeViewDelegate>

@property (nonatomic, strong) GYRollingNoticeView *noticeView;


@end

@implementation LJProfessionalAnswerCell

+ (CGFloat)calculateHeight {
    
    CGFloat headHeight = (TTScreenWidth - 26)*0.10888 ;
    CGFloat collectionHeight = 70 ;
    CGFloat btnHeight = 36 ;
    CGFloat scrollHeight = 40 ;

    return headHeight + collectionHeight + btnHeight + scrollHeight +25;
}

- (void)awakeFromNib {
    [super awakeFromNib];


    [self initView];
}

- (void)fillWith:(NSMutableArray <CommunitySellerModel*>*)storeArray
             And:(NSMutableArray <CommunitySellerModel*>*)askArray {
    
    self.storeArray = @[].mutableCopy;
    self.askArray = @[].mutableCopy;
    
    self.storeArray = storeArray;
    self.askArray = askArray;
    
    [self.collectionview reloadData];
    [self.noticeView reloadDataAndStartRoll];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.askBtn pp_clipCorners:UIRectCornerAllCorners radius:self.askBtn.frame.size.height/2];

    });
    
    self.cornerRediusView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    self.cornerRediusView.layer.cornerRadius = 8;
    self.cornerRediusView.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.06].CGColor;
    self.cornerRediusView.layer.shadowOffset = CGSizeMake(0,2);
    self.cornerRediusView.layer.shadowOpacity = 1;
    self.cornerRediusView.layer.shadowRadius = 10;
}

- (void)initView {
    
    UICollectionViewFlowLayout *flowLaout = [[UICollectionViewFlowLayout alloc]init];
    flowLaout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    flowLaout.minimumInteritemSpacing = 0;
    flowLaout.minimumLineSpacing = 0;
    
    flowLaout.itemSize = CGSizeMake(160, 70);

    self.collectionview.collectionViewLayout = flowLaout;
    self.collectionview.delegate = self;
    self.collectionview.dataSource = self;
    self.collectionview.showsHorizontalScrollIndicator = NO;
    self.collectionview.showsVerticalScrollIndicator = NO;
    
    [self.collectionview registerNib:[UINib nibWithNibName:@"LJTalentCell" bundle:nil] forCellWithReuseIdentifier:@"LJTalentCellID"];
    
    [self.scrollBGView addSubview:self.noticeView];
    [self.noticeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(25);
        make.right.mas_equalTo(-25);
    }];
    
}

- (IBAction)askAction:(id)sender {
    if (self.LJProfessionalAnswerCellBlock) {
        self.LJProfessionalAnswerCellBlock(LJAnswerActionType_ask, -1);
    }
}

- (NSInteger)numberOfRowsForRollingNoticeView:(GYRollingNoticeView *)rollingView {
    return self.askArray.count;
}

- (__kindof GYNoticeViewCell *)rollingNoticeView:(GYRollingNoticeView *)rollingView cellAtIndex:(NSUInteger)index {
    
    MineRecNoticeCell *cell = [rollingView dequeueReusableCellWithIdentifier:@"MineRecNoticeCell"];

    [cell.notiImage sd_setImageWithURL:[NSURL URLWithString:self.askArray[index].userHeadUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    cell.notiLab.text = [NSString stringWithFormat:@"%@向婚礼人提问‘%@’",self.askArray[index].userNickName,self.askArray[index].mqContent];

    return cell;
}

//轮播的点击事件
- (void)didClickRollingNoticeView:(GYRollingNoticeView *)rollingView forIndex:(NSUInteger)index {
    if (self.LJProfessionalAnswerCellBlock) {
        self.LJProfessionalAnswerCellBlock(LJAnswerActionType_userAsk, index);
    }
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    LJTalentCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LJTalentCellID" forIndexPath:indexPath];
    CommunitySellerModel *model = self.storeArray[indexPath.row];
    [cell fillWithModel:model];
    
    return cell;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.storeArray.count;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    if (self.LJProfessionalAnswerCellBlock) {
        self.LJProfessionalAnswerCellBlock(LJAnswerActionType_store, indexPath.row);
    }
}

- (GYRollingNoticeView *)noticeView {
    
    if (!_noticeView) {
        _noticeView = [[GYRollingNoticeView alloc]init];
        _noticeView.dataSource = self;
        _noticeView.delegate = self;
        _noticeView.stayInterval = 3;
        _noticeView.backgroundColor = [UIColor whiteColor];
        [_noticeView registerClass:[MineRecNoticeCell class] forCellReuseIdentifier:@"MineRecNoticeCell"];
        
    }
    return _noticeView;
}

@end
